package jdo.crud;

import java.io.IOException;
import javax.jdo.PersistenceManager;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import jdo.entity.Metro;
import jdo.pmf.PMF;

/**
 * Servlet implementation class ListServlet
 */
@SuppressWarnings("serial")
public class DeleteMetroServlet extends HttpServlet {

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException,
			IOException {
		PersistenceManager pm = PMF.getPersistenceManager();
		long id_metro = Long.parseLong(request.getParameter("metroid_metro"));
		Metro metro = pm.getObjectById(Metro.class, id_metro);
		String resultat;
		if (metro != null) {
			pm.deletePersistent(metro);
			resultat = "deletedOK";
		} else {
			resultat = "alreadyDeleted";
		}
		pm.close();
		response.sendRedirect("/administration.jsp?message="+resultat);
	}

}
